/**
 * Created with IntelliJ IDEA.
 * User: chenkaiyu
 * Date: 15-5-24
 * Time: 下午6:16
 * To change this template use File | Settings | File Templates.
 */

var airGas = function(){

    var AirGasParameter = {
        E31: $("#E31"),
        E32: $("#E32"),
        E33: $("#E33"),
        E34: $("#E34"),
        E35: $("#E35"),
        E42: $("#E42"),
        E43: $("#E43"),
        E44: $("#E44"),
        E45: $("#E45"),
        E46: $("#E46"),
        E50: $("#E50"),
        E36: $("#E36"),
        E37: $("#E37"),
        E38: $("#E38"),
        E39: $("#E39"),
        E40: $("#E40"),
        E41: $("#E41"),
        E61: $("#E61"),
        E63: $("#E63"),
        E28: $("#E28")
    };
    return{
        init:function(){
            $("#airGas_E31").blur(function(){
                var $obj = $("#airGas_E31");
                var E31 = $obj.val();
                validate.init($obj);
                if(E31!=""){
                    if(validate.isNotNumber(E31)){
                        validate.invalid();
                        return;
                    }
                    validate.valid();
                    $.ajax({
                        url: basePath + "boiler/airGas/saveTheValueOfE31",
                        dataType:"json",
                        type:"post",
                        data:"E31=" + E31
                    }).done(function (){
                        $.ajax({
                            url:basePath+"boiler/airGas/calculateE36",
                            contentType: "application/json;charset=utf-8",
                            dataType:"json",
                            type: "post",
                            success:function(data){
                                $("#E36_show").html(data.returnMsg);
                            }
                        })
                    })
                }else{
                    validate.invalid();
                }
            });

            $("#check").on('click',function() {
                $('#modal').modal('show');
                $("#Y").hide();
                $("#N").hide();
                $.ajax({
                    url: basePath + "result/calculateE49",
                    type: "POST",
                    dataType:"json",
                    success: function(data) {
                        $('#modal').modal('show');
                        $("#res").html(data.returnMsg);
                        if((data.returnMsg) < $("#airGas_E50").val()) {
                            $("#Y").show();
                            $("#N").hide();
                        } else {
                            $("#N").show();
                            $("#Y").hide();
                        }
                    }
                })
            });

            $("#airGas_E32").blur(function(){
                var $obj = $("#airGas_E32");
                var E32 = $obj.val();
                validate.init($obj);

                if(E32!=""){
                    if(validate.isNotNumber(E32)){
                        validate.invalid();
                        return;
                    }
                    validate.valid();
                    $.ajax({
                        url: basePath + "boiler/airGas/saveTheValueOfE32",
                        dataType:"json",
                        type:"post",
                        data:"E32=" + E32
                    }).done(function (){
                        $.ajax({
                            url:basePath+"boiler/airGas/calculateE37",
                            contentType: "application/json;charset=utf-8",
                            dataType:"json",
                            type: "post",
                            success:function(data){
                                $("#E37_show").html(data.returnMsg);
                            }
                        })
                    })
                }else{
                    validate.invalid();
                }
            });

            $("#airGas_E33").blur(function(){
                var $obj = $("#airGas_E33");
                var E33 = $obj.val();
                validate.init($obj);

                if(E33!=""){
                    if(validate.isNotNumber(E33)){
                        validate.invalid();
                        return;
                    }
                    validate.valid();
                    $.ajax({
                        url: basePath + "boiler/airGas/saveTheValueOfE33",
                        dataType:"json",
                        type:"post",
                        data:"E33=" + E33
                    }).done(function (){
                        $.ajax({
                            url:basePath+"boiler/airGas/calculateE38",
                            contentType: "application/json;charset=utf-8",
                            dataType:"json",
                            type: "post",
                            success:function(data){
                                $("#E38_show").html(data.returnMsg);
                            }
                        })
                    })
                }else{
                    validate.invalid();
                }
            });

            $("#airGas_E34").blur(function(){
                var $obj = $("#airGas_E34");
                var E34 = $obj.val();
                validate.init($obj);

                if(E34!=""){
                    if(validate.isNotNumber(E34)){
                        validate.invalid();
                        return;
                    }
                    validate.valid();
                    $.ajax({
                        url: basePath + "boiler/airGas/saveTheValueOfE34",
                        dataType:"json",
                        type:"post",
                        data:"E34=" + E34
                    }).done(function (){
                        $.ajax({
                            url:basePath+"boiler/airGas/calculateE39",
                            contentType: "application/json;charset=utf-8",
                            dataType:"json",
                            type: "post",
                            success:function(data){
                                $("#E39_show").html(data.returnMsg);
                            }
                        })
                    })
                }else{
                    validate.invalid();
                }
            });

            $("#airGas_E35").blur(function(){
                var $obj = $("#airGas_E35");
                var E35 = $obj.val();
                validate.init($obj);

                if(E35!=""){
                    if(validate.isNotNumber(E35)){
                        validate.invalid();
                        return;
                    }
                    validate.valid();
                    $.ajax({
                        url: basePath + "boiler/airGas/saveTheValueOfE35",
                        dataType:"json",
                        type:"post",
                        data:"E35=" + E35
                    }).done(function (){
                        $.ajax({
                            url:basePath+"boiler/airGas/calculateE40",
                            contentType: "application/json;charset=utf-8",
                            dataType:"json",
                            type: "post",
                            success:function(data){
                                $("#E40_show").html(data.returnMsg);
                                $.ajax({
                                    url:basePath+"boiler/airGas/calculateE41",
                                    contentType: "application/json;charset=utf-8",
                                    dataType:"json",
                                    type: "post",
                                    success:function(data){
                                        $("#E41_show").html(data.returnMsg);
                                    }
                                })
                            }
                        })
                    })
                }else{
                    validate.invalid();
                }
            });

            $("#airGas_E42").blur(function(){
                var $obj = $("#airGas_E42");
                var E42 = $obj.val();
                validate.init($obj);

                if(E42!=""){
                    if(validate.isNotNumber(E42)){
                        validate.invalid();
                        return;
                    }
                    validate.valid();
                    $.ajax({
                        url: basePath + "boiler/airGas/saveTheValueOfE42",
                        dataType:"json",
                        type:"post",
                        data:"E42=" + E42
                    }).done(function (){
                        $.ajax({
                            url:basePath+"boiler/airGas/calculateE61",
                            contentType: "application/json;charset=utf-8",
                            dataType:"json",
                            type: "post",
                            success:function(data){
                                $("#E61_show").html(data.returnMsg);
                            }
                        })
                    })
                }else{
                    validate.invalid();
                }
            });

            $("#airGas_E43").blur(function(){
                var $obj = $("#airGas_E43");
                var E43 = $obj.val();
                validate.init($obj);

                if(E43!=""){
                    if(validate.isNotNumber(E43) ||E43>100){
                        validate.invalid();
                        return;
                    }
                    validate.valid();
                    $.ajax({
                        url: basePath + "boiler/airGas/saveTheValueOfE43",
                        dataType:"json",
                        type:"post",
                        data:"E43=" + E43
                    })
                }else{
                    validate.invalid();
                }

            });

            $("#airGas_E44").blur(function(){
                var $obj = $("#airGas_E44");
                var E44 = $obj.val();
                validate.init($obj);
                if(E44!=""){
                    if(validate.isNotNumber(E44) ||E44>100){
                        validate.invalid();
                        return;
                    }
                    validate.valid();
                    $.ajax({
                        url: basePath + "boiler/airGas/saveTheValueOfE44",
                        dataType:"json",
                        type:"post",
                        data:"E44=" + E44
                    })
                }else{
                    validate.invalid();
                }

            });

            $("#airGas_E45").blur(function(){
                var $obj = $("#airGas_E45");
                var E45 = $obj.val();
                validate.init($obj);

                if(E45!=""){
                    if(validate.isNotNumber(E45)){
                        validate.invalid();
                        return;
                    }
                    validate.valid();
                    $.ajax({
                        url: basePath + "boiler/airGas/saveTheValueOfE45",
                        dataType:"json",
                        type:"post",
                        data:"E45=" + E45
                    })
                }else{
                    validate.invalid();
                }

            });

            $("#airGas_E46").blur(function(){
                var $obj = $("#airGas_E46");
                var E46 = $obj.val();
                validate.init($obj);

                if(E46!=""){
                    if(validate.isNotNumber(E46) ||E46>100){
                        validate.invalid();
                        return;
                    }
                    validate.valid();
                    $.ajax({
                        url: basePath + "boiler/airGas/saveTheValueOfE46",
                        dataType:"json",
                        type:"post",
                        data:"E46=" + E46
                    })
                }else{
                    validate.invalid();
                }
            });

            $("#airGas_E28").blur(function(){
                var $obj = $("#airGas_E28");
                var E28 = $obj.val();
                validate.init($obj);
                if(E28!=""){
                    if(validate.isNotNumber(E28) ||E28>100){
                        validate.invalid();
                        return;
                    }
                    validate.valid();
                    $.ajax({
                        url: basePath + "boiler/airGas/saveTheValueOfE28",
                        dataType:"json",
                        type:"post",
                        data:"E28=" + E28
                    })
                }else{
                    validate.invalid();
                }

            });

            $("#airGas_E111 option").click(function () {
                var E111 = $("#airGas_E111").val();
                $.ajax({
                    url: basePath + "boiler/airGas/saveTheValueOfE111",
                    dataType:"json",
                    type:"post",
                    data:"E111=" + E111
                })
            });

            $("#airGas_E50").blur(function(){
                var $obj = $("#airGas_E50");
                var E50 = $obj.val();
                validate.init($obj);

                if(E50!=""){
                    if(validate.isNotNumber(E50)){
                        validate.invalid();
                        return;
                    }
                    validate.valid();
                    $.ajax({
                        url: basePath + "boiler/airGas/saveTheValueOfE50",
                        dataType:"json",
                        type:"post",
                        data:"E50=" + E50
                    })
                }else{
                    validate.invalid();
                    return;
                }
                $.ajax({
                    url:basePath+"boiler/airGas/calculateE63",
                    contentType: "application/json;charset=utf-8",
                    dataType:"json",
                    type: "post",
                    success:function(data){
                        $("#E63_show").html(data.returnMsg);
                    }
                })
            });

            $("#nextPage").on("click",function (){
                    window.location.href = basePath + "boiler/efficiency?menuId=20"
            });

//            window.onunload = function(){
//                $.ajax({
//                    url:basePath+"result/culAll",
//                    contentType: "application/json;charset=utf-8",
//                    dataType:"json",
//                    type: "post"
//                })
//            }
            
        },
        recover: function () {
            $.each(AirGasParameter, function (key, jqObj) {
                jqObj.val(getValidRecoverVal(jqObj.val()));
            })
        }
    }
}();
